package com.goods.controller.business;

import com.goods.business.service.OutStockService;
import com.goods.common.response.ResponseBean;
import com.goods.common.utils.ListPageUtils;
import com.goods.common.vo.business.OutStockDetailVO;
import com.goods.common.vo.business.OutStockVO;
import com.goods.common.vo.system.PageVO;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "发放记录 ")
@RestController
@RequestMapping("business/outStock")
public class OutStockController {
    @Resource
    private OutStockService outStockService;

    @GetMapping("/findOutStockList")
    public ResponseBean findOutStockList(OutStockVO outStockVO, Integer pageNum, Integer pageSize) {
        List<OutStockVO> list = outStockService.findOutStockList(outStockVO);
        List<OutStockVO> page = ListPageUtils.page(list, pageSize, pageNum);
        return ResponseBean.success(new PageVO<>(list.size(), page));
    }

    //明细
    @GetMapping("/detail/{id}")
    public ResponseBean detail(@PathVariable Long id,
                               Integer pageNum) {
        OutStockDetailVO outStockDetail = outStockService.findOutStockDetail(id);
        return ResponseBean.success(outStockDetail);
    }
    //移入回收站
    @PutMapping("/remove/{id}")
    public ResponseBean remove(@PathVariable Long id) {
        Integer status = 1;
        Integer integer = outStockService.removeAndBack(id,status);
        if (integer > 0) {
            return ResponseBean.success();
        } else {
            return ResponseBean.error("移入回收站失败惹");
        }
    }
    //从回收站恢复
    @PutMapping("/back/{id}")
    public ResponseBean back(@PathVariable Long id) {
        Integer status = 0;
        Integer integer = outStockService.removeAndBack(id,status);
        if (integer > 0) {
            return ResponseBean.success();
        } else {
            return ResponseBean.error("恢复失败惹");
        }
    }
    //删除
    @GetMapping("/delete/{id}")
    public ResponseBean update(@PathVariable Long id) {
        Integer integer = outStockService.delete(id);
        if (integer > 0) {
            return ResponseBean.success();
        } else {
            return ResponseBean.error("删除失败惹");
        }
    }
    //入库
    @PostMapping("/addOutStock")
    public ResponseBean addIntoStock(@RequestBody OutStockVO outStockVO) {
        Integer integer = outStockService.addIntoStock(outStockVO);
        if (integer > 0) {
            return ResponseBean.success();
        } else {
            return ResponseBean.error("添加失败惹");
        }
    }
    //审核
    @PutMapping("/publish/{id}")
    public ResponseBean publish(@PathVariable Long id){
        Integer integer = outStockService.publish(id);
        return ResponseBean.success();
    }
}
